import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { CmtContentFeedbackApi } from '#/api/cmt/content/feedback';

import { getBaseCommunityOptions } from '#/api/cmt/base/community';
import { getMerchantInfoOptions } from '#/api/cmt/base/merchantInfo';
import { getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'communityId',
      label: '社区',
      component: 'ApiSelect',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请选择社区',
        api: getBaseCommunityOptions,
        resultField: 'list',
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      fieldName: 'merchantId',
      label: '商户',
      component: 'ApiSelect',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请选择商户',
        api: getMerchantInfoOptions,
        resultField: 'list',
        labelField: 'name',
        valueField: 'id',
      },
    },
    {
      fieldName: 'userId',
      label: '反馈会员',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入反馈会员ID',
      },
    },
    {
      fieldName: 'feedbackType',
      label: '反馈类型',
      rules: 'required',
      component: 'RadioGroup',
      formItemClass: 'col-span-1',
      componentProps: {
        options: [
          { label: '系统问题', value: 1 },
          { label: '活动建议', value: 2 },
          { label: '服务建议', value: 3 },
          { label: '其他', value: 4 },
        ],
      },
      defaultValue: 1,
    },
    {
      fieldName: 'category',
      label: '分类',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入分类',
      },
    },
    {
      fieldName: 'title',
      label: '标题',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入标题',
      },
    },
    {
      fieldName: 'content',
      label: '反馈内容',
      rules: 'required',
      component: 'Input',
      formItemClass: 'col-span-2',
      componentProps: {
        type: 'textarea',
        rows: 5,
        placeholder: '请输入反馈内容',
      },
    },
    {
      fieldName: 'images',
      label: '图片',
      component: 'ImageUpload',
      formItemClass: 'col-span-2',
      componentProps: {
        multiple: true,
      },
    },
    {
      fieldName: 'contactPhone',
      label: '联系电话',
      component: 'Input',
      formItemClass: 'col-span-2',
      componentProps: {
        placeholder: '请输入联系电话',
      },
    },
    {
      fieldName: 'feedbackStatus',
      label: '处理状态',
      component: 'RadioGroup',
      formItemClass: 'col-span-2',
      componentProps: {
        options: [
          { label: '待处理', value: 0 },
          { label: '处理中', value: 1 },
          { label: '已处理', value: 2 },
          { label: '已采纳', value: 3 },
        ],
      },
      defaultValue: 0,
    },
    {
      fieldName: 'reply',
      label: '回复内容',
      component: 'Input',
      formItemClass: 'col-span-2',
      componentProps: {
        type: 'textarea',
        rows: 3,
        placeholder: '请输入回复内容',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'title',
      label: '标题',
      component: 'Input',
      componentProps: {
        clearable: true,
        placeholder: '请输入标题',
      },
    },
    {
      fieldName: 'userId',
      label: '反馈会员',
      component: 'Input',
      componentProps: {
        clearable: true,
        placeholder: '请输入反馈会员ID',
      },
    },
    {
      fieldName: 'feedbackType',
      label: '反馈类型',
      component: 'Select',
      componentProps: {
        clearable: true,
        options: [
          { label: '系统问题', value: 1 },
          { label: '活动建议', value: 2 },
          { label: '服务建议', value: 3 },
          { label: '其他', value: 4 },
        ],
        placeholder: '请选择反馈类型',
      },
    },
    {
      fieldName: 'feedbackStatus',
      label: '处理状态',
      component: 'Select',
      componentProps: {
        clearable: true,
        options: [
          { label: '待处理', value: 0 },
          { label: '处理中', value: 1 },
          { label: '已处理', value: 2 },
          { label: '已采纳', value: 3 },
        ],
        placeholder: '请选择处理状态',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        clearable: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<CmtContentFeedbackApi.Feedback>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '反馈ID',
      minWidth: 100,
    },
    {
      field: 'title',
      title: '标题',
      minWidth: 180,
    },
    {
      field: 'userId',
      title: '反馈会员',
      minWidth: 100,
    },
    {
      field: 'feedbackType',
      title: '反馈类型',
      minWidth: 120,
      slots: { default: 'feedbackType' },
    },
    {
      field: 'category',
      title: '分类',
      minWidth: 100,
    },
    {
      field: 'content',
      title: '反馈内容',
      minWidth: 250,
    },
    {
      field: 'contactPhone',
      title: '联系电话',
      minWidth: 120,
    },
    {
      field: 'feedbackStatus',
      title: '处理状态',
      minWidth: 100,
      slots: { default: 'feedbackStatus' },
    },
    {
      field: 'reply',
      title: '回复内容',
      minWidth: 200,
    },
    {
      field: 'replyTime',
      title: '回复时间',
      minWidth: 160,
      formatter: 'formatDateTime',
    },
    {
      field: 'likeCount',
      title: '点赞数',
      minWidth: 100,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 160,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
